package com.mhh.selary.backend.controller.user;

import com.mhh.sdk.beans.LoginUserContext;
import com.mhh.sdk.beans.annotation.WhiteList;
import com.mhh.selary.backend.api.user.ISelaryUserAccountService;
import com.mhh.selary.backend.config.SystemConstants;
import com.mhh.selary.backend.dto.user.LoginDTO;
import com.mhh.selary.backend.dto.user.LoginSuccessDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author mhh
 * @date 2020-11-11 16:30:37
 */
@Slf4j
@RestController
@Api(tags = "登录/登出模块")
public class LoginController {

    @Autowired
    private ISelaryUserAccountService selaryUserAccountService;

    @WhiteList
    @PostMapping("login")
    @ApiOperation("登录")
    public LoginSuccessDTO login(@RequestBody LoginDTO loginDTO) {
        return selaryUserAccountService.login(loginDTO);
    }

    @PostMapping("logout")
    @ApiOperation("登出")
    public void logout() {
        SystemConstants.removeLoginToken(LoginUserContext.get().getUserId());
    }
}
